package com.devilvan.betrice.opgg.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.devilvan.betrice.opgg.dto.OpggChampionMetaDto;
import com.devilvan.betrice.opgg.po.OpggChampionMetaPo;
import com.devilvan.betrice.opgg.service.OpggChampionMetaService;
import com.devilvan.betrice.opgg.mapper.OpggChampionMetaMapper;
import com.devilvan.betrice.opgg.repository.OpggChampionMetaRepository;
import com.devilvan.betrice.util.UCopy;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.sql.SQLException;
import java.util.List;

/**
 * @author Evad.Wu
 * @Description OPGG-英雄信息 业务逻辑类
 * @date 2022-10-04
 */
@Service
public class OpggChampionMetaServiceImpl extends ServiceImpl<OpggChampionMetaMapper, OpggChampionMetaPo> implements OpggChampionMetaService {
    @Resource(name = "opggChampionMetaRepository")
    private OpggChampionMetaRepository opggChampionMetaRepository;

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public OpggChampionMetaPo saveUpdate(OpggChampionMetaDto opggChampionMetaDto) {
        OpggChampionMetaPo opggChampionMetaPo = new OpggChampionMetaPo();
        UCopy.fullCopy(opggChampionMetaDto, opggChampionMetaPo);
        return opggChampionMetaRepository.saveAndFlush(opggChampionMetaPo);
    }

    @Override
    @Transactional(rollbackFor = {SQLException.class, ArithmeticException.class})
    public List<OpggChampionMetaPo> saveUpdateBatch(List<OpggChampionMetaDto> list) {
        List<OpggChampionMetaPo> opggChampionMetaPoList = UCopy.fullCopyCollections(list, OpggChampionMetaPo.class);
        return opggChampionMetaRepository.saveAllAndFlush(opggChampionMetaPoList);
    }
}
